﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace GirisSayfasi
{
    public partial class OgrenciArama : Form
    {
        public static string Ogrenci_Tc;
        public OgrenciKayit anaform;

        MySqlConnection baglan = Connection.baglan;

        public OgrenciArama()
        {
            InitializeComponent();
        }

        private void OgrenciArama_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
            if(e.KeyCode == Keys.Enter) 
            {

                lstOgrenciBilgileri.Items.Clear();
                                
                baglan.Open();
                MySqlCommand cmd1 = new MySqlCommand("SELECT OgrenciTc, OgrenciAdi, OgrenciSoyadi FROM ogrencilistesi Where OgrenciAdi LIKE @txtOgrenciAdi '%' AND OgrenciSoyadi LIKE @txtOgrenciSoyadi '%'", baglan);
                cmd1.Parameters.AddWithValue("@txtOgrenciAdi", txtOgrenciAdi.Text);
                cmd1.Parameters.AddWithValue("@txtOgrenciSoyadi", txtOgrenciSoyadi.Text);
                cmd1.ExecuteScalar();
                    MySqlDataReader oku1 = cmd1.ExecuteReader();
                    if (oku1.HasRows)
                    {
                        while (oku1.Read())
                        {
                            ListViewItem lst = new ListViewItem();
                            lst.Text = oku1["OgrenciAdi"].ToString();
                            lst.SubItems.Add(oku1["OgrenciSoyadi"].ToString());
                            lst.Tag = oku1["OgrenciTc"];
                            lstOgrenciBilgileri.Items.Add(lst);

                        }
                    }

                baglan.Close();
            }


        }
               

        private void OgrenciArama_Activated(object sender, EventArgs e)
        {
            lstOgrenciBilgileri.Items.Clear();
            txtOgrenciAdi.Clear();
            txtOgrenciSoyadi.Clear();
            txtOgrenciAdi.Focus();
        }

        private void lstOgrenciBilgileri_DoubleClick(object sender, EventArgs e)
        {
            OgrenciKayit frm2 = (OgrenciKayit)Application.OpenForms["OgrenciKayit"];
            ///OgrenciKayit frm2 = new OgrenciKayit();
            frm2.mskOgrenciTc.Text = lstOgrenciBilgileri.SelectedItems[0].Tag.ToString();
            this.Hide();

        } 
          } 
             
        }

    

